package com.example.cslp.controller;

import com.example.cslp.pojo.entity.Notice;
import com.example.cslp.service.NoticeService;
import com.example.cslp.util.TimeUtil;
import com.example.cslp.web.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/notice")
public class NoticeController {
    @Autowired
    NoticeService noticeService;
    //创建公告
    @RequestMapping("/createNotice")
    public JsonResult createNotice(@RequestBody Notice notice){
        //导入时间
        TimeUtil timeUtil=new TimeUtil();
        notice.setCreateDate(timeUtil.getCurrentTimePlus());
        return JsonResult.ok(noticeService.createNotice(notice),"公告创建成功");
    }

    //编辑公告
    @RequestMapping("/editNotice")
    public JsonResult editNotice(@RequestBody Notice notice){
        //导入时间
        TimeUtil timeUtil=new TimeUtil();
        notice.setCreateDate(timeUtil.getCurrentTimePlus());
        return JsonResult.ok(noticeService.editNotice(notice),"公告编辑成功");
    }

    //
    @RequestMapping("/queryNotice")
    public JsonResult queryNotice(){
        return JsonResult.ok(noticeService.queryNotice(),"查询成功");
    }

    @RequestMapping("/deleteNotice")
    public JsonResult deleteNotice(@RequestBody Notice notice){
        return JsonResult.ok(noticeService.deleteNotice(notice),"删除成功");
    }
}
